package bing

import (
	"errors"
	"io/ioutil"
	"net/http"
	"strings"
)

type Data struct {
	images string
}

func Background_GetURL() (string, error) {
	var url string

	url = "http://cn.bing.com/HPImageArchive.aspx?format=js&idx=0&n=1"

	resp, err := http.Get(url)
	if err != nil {
		return "", err
	}

	defer resp.Body.Close()
	body, err := ioutil.ReadAll(resp.Body)
	if err != nil {
		return "", err
	}

	// 判断状态 有没有resoult
	context := string(body)
	if strings.Contains(context, "{\"images\":") {
		return context, nil
	}

	// 不包含
	LogFile.Println("天气接口调用出错-获取天气")
	return "nil", errors.New(context)
}
